package be.jprojects.subscription.gui.detailpanels;

import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import com.toedter.calendar.JDateChooser;


import be.jprojects.subscription.controllers.LanguageController;
import be.jprojects.subscription.controllers.ListenersController;
import be.jprojects.subscription.gui.listeners.CRUDActionListener;
import be.jprojects.subscription.gui.listeners.SelectedPersonChangeListener;
import be.jprojects.subscription.logic.interfaces.IPerson;

public class PersonDetailPanel extends DetailPanel implements SelectedPersonChangeListener {
	private JFrame frame;
	private JLabel firstNameLabel, lastNameLabel, middleNameLabel, dateOfBirthLabel;
	private JTextField firstNameTextField, lastNameTextField, middleNameTextField;
	private JDateChooser dateOfBirthChooser;
	
	public PersonDetailPanel(JFrame frame) {
		super("Person");
		super.setName("Person");
		this.frame = frame;
		
		GroupLayout layout = new GroupLayout(this);
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        
        this.setLayout(layout);
		
		firstNameLabel = new JLabel("FirstName");
		lastNameLabel = new JLabel("LastName");
		middleNameLabel = new JLabel("MiddleName");
		dateOfBirthLabel = new JLabel("DateOfBirth");
		
		firstNameTextField = new JTextField();
		lastNameTextField = new JTextField();
		middleNameTextField = new JTextField();
		dateOfBirthChooser = new JDateChooser();

		enableAll(false);
		
		layout.setHorizontalGroup(layout.createSequentialGroup()
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
					.addComponent(firstNameLabel)
					.addComponent(middleNameLabel)
					.addComponent(lastNameLabel)
					.addComponent(dateOfBirthLabel))
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)	
					.addComponent(lastNameTextField)
					.addComponent(middleNameTextField)
					.addComponent(firstNameTextField)
					.addComponent(dateOfBirthChooser))
					);
		
		layout.setVerticalGroup(layout.createSequentialGroup()
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)	
					.addComponent(firstNameLabel)
					.addComponent(firstNameTextField))				
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)	
					.addComponent(middleNameLabel)
					.addComponent(middleNameTextField))
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)	
					.addComponent(lastNameLabel)
					.addComponent(lastNameTextField))
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)	
					.addComponent(dateOfBirthLabel)
					.addComponent(dateOfBirthChooser))	
					);

		ListenersController.getInstance().addSelectedPersonChangeListener(this);
	}

	@Override
	public void selectedPersonChanged(IPerson person) {
		if (person!=null) {
			firstNameTextField.setText(person.getFirstName());
			lastNameTextField.setText(person.getLastName());
			middleNameTextField.setText(person.getMiddleName());
		}
	}
	


	@Override
	public void cancelCreationActionPerformed() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cancelDeletionActionPerformed() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cancelUpdateActionPerformed() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void saveCreationActionPerformed() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void saveDeletionActionPerformed() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void saveUpdateActionPerformed() {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void enableAll(boolean enableAll) {
		firstNameTextField.setEnabled(enableAll);
		lastNameTextField.setEnabled(enableAll);
		middleNameTextField.setEnabled(enableAll);
		dateOfBirthChooser.setEnabled(enableAll);
	}

	@Override
	public void clearAll() {
		firstNameTextField.setText("");
		lastNameTextField.setText("");
		middleNameTextField.setText("");
		dateOfBirthChooser.setDate(null);
	}

}
